package com.interview.ujiuye4;

import java.util.concurrent.TimeUnit;
//static User.class 非静态方法的锁 对象
class User{
    public synchronized void save(){
        System.out.println(Thread.currentThread().getName()+"执行save方法");
        try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); }
    }

    public synchronized void update(){
        System.out.println(Thread.currentThread().getName()+"执行update方法");
    }

    public static synchronized void delete(){
        System.out.println(Thread.currentThread().getName()+"执行delete方法");
    }
}



public class Demo1 {

    public static void main(String[] args) {
        User user = new User();
        new Thread( () ->{
            user.save();
        },"AAA" ).start();

        new Thread( () ->{
            user.delete();
        },"BBB" ).start();
    }
}
